package shiro.authc.config;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 李岩峰
 * @date 2017/11/21 14:39
 * @description
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter
{

	public void configureMessageConverters(List<HttpMessageConverter<?>> converters)
	{
		super.configureMessageConverters(converters);
		FastJsonHttpMessageConverter fastJsonConverter = new FastJsonHttpMessageConverter();
		FastJsonConfig fastJsonConfig = new FastJsonConfig();
		//2.添加fastJson的配置信息,比如，是否需要格式化返回的json数据
		fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);

		//处理中文乱码问题
		List<MediaType> mediaTypes = new ArrayList<>();
		//设置返回的json编码格式
		mediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
		fastJsonConverter.setSupportedMediaTypes(mediaTypes);
		fastJsonConverter.setFastJsonConfig(fastJsonConfig);
		converters.add(fastJsonConverter);
	}
}
